﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#include "../import/head.h"
#include "mutex.h"

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 

namespace xos
{

    mutex::mutex()
    {
        m_hMutex = ::CreateMutex( NULL, FALSE, NULL );
    }

    mutex::~mutex()
    {
        ::CloseHandle( m_hMutex );
        m_hMutex = 0;
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // method

    int mutex::un_lock()
    {
        int nRet = 0;
        ReleaseMutex( m_hMutex );
        return nRet;
    }

    int mutex::lock()
    {
        int nRet = 0;
        WaitForSingleObject( m_hMutex,INFINITE );
        return nRet;
    }

} // xos
